﻿@{
	PageData["Title"] = "Login";
	var username = "";
	var rememberMe = true;
}

<h1>Login</h1>
@if (IsPost) {
	username = Request["username"];
	var password = Request["password"];
	rememberMe = Request["rememberMe"].AsBool();
	var returnUrl = Request.QueryString["ReturnUrl"] ?? "~/ManageLists";
    var errorMessage = "";
    //Log user in, detecting if they are unconfirmed and prompting them as appropriate
	if (!username.IsEmpty() && !password.IsEmpty()) {
		if (WebSecurity.Login(username, password, rememberMe)) {
			Context.RedirectLocal(returnUrl);
		} else {
            if (!WebSecurity.IsConfirmed(username) && WebSecurity.GetUserId(username) != -1) {
			    errorMessage = "<li>Your account is not confirmed.  Please check your e-mail.</li>";
            } else {
                errorMessage = "<li>Login failed.  Please try again.</li>";
            }
		}
	} else {
		errorMessage = "<li>Username or password cannot be empty!</li>";
	}
    if (!errorMessage.IsEmpty()) {
        @RenderPage("~/Shared/Errors/_FormInputError.cshtml", errorMessage);
    }
}
Use the form below to login: 
<div>
    <form id="validateForm" method="post" action="">
	    <fieldset>
		    @RenderPage("~/Shared/_PrePopInputFormField.cshtml", 
                new {labelName = "username", labelDisplay = "Username:", inputValue = username, maxLength = 30, required = true})
		    @RenderPage("~/Shared/_InputFormField.cshtml", 
                new {labelName = "password", labelDisplay = "Password:", inputType = "password", required = true})
		    @RenderPage("~/Shared/_PrePopInputFormField.cshtml", 
                new {labelName = "rememberMe", labelDisplay = "Remember Me?", inputType = "checkbox", inputValue = rememberMe.ToString(), required = true})
		    <div class="submit-group">
			    <input type="submit" value="Login" onclick="javascript:$('#validateForm').validate()" />
		    </div>
            <div>
                <a href="@Href("~/Account/ForgotPassword")">Forgot your password?</a>
            </div>
	    </fieldset>
    </form>

</div>
<div class="message">
    <h3>Hint (only for sample purposes):</h3>
    <p>To login as Administrator and manage user accounts and the Freemium model, use the following user/password:</p>
    <ul>                
        <li><strong>Administrator: </strong><span>admin / 123456</span></li>
    </ul>
    <p>Additionally, the following used accounts have been pre-provisioned for testing the different SKUs and their associated features:</p>
    <ul>                
        <li><strong>Gold SKU: </strong><span>gold-user / 123456</span></li>
        <li><strong>Silver SKU: </strong><span>silver-user / 123456</span></li>
    </ul>
</div>